package team.szm.scd.service.impl;

import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
import team.szm.scd.database.entity.Doctor;
import team.szm.scd.database.entity.User;
import team.szm.scd.service.interfaces.ILoginService;
import team.szm.scd.utils.EncodeUtils;

import javax.annotation.Resource;
import javax.print.Doc;
import javax.servlet.http.HttpSession;
import java.security.NoSuchAlgorithmException;

@Service
@Profile("test")
public class TestLoginServiceImpl implements ILoginService {

    public final static User testUser = new User();
    public final static Doctor testDoctor = new Doctor();

    static {
        testUser.setId("1");
        try {
            testUser.setPassword(EncodeUtils.SHA256("123"));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        testUser.setId2("2");
        testUser.setGender(false);
        testUser.setAddress("测试地址");
        testUser.setName("测试用户");
        testDoctor.setId("1");
        try {
            testDoctor.setPassword(EncodeUtils.SHA256("123"));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
        testDoctor.setName("测试医生2");
        testDoctor.setExpert(false);
        testDoctor.setDepartmentId(1);
        testDoctor.setHospitalId(1);
    }

    @Override
    public User getLoginUser(HttpSession session) {
        session.setAttribute(User.USER_SESSION_STR, testUser);
        return testUser;
    }

    @Override
    public Doctor getLoginDoctor(HttpSession session) {
        session.setAttribute(Doctor.DOCTOR_SESSION_STR, testDoctor);
        return testDoctor;
    }
}
